package com.wanyang.controller;

import com.wanyang.dto.*;
import com.wanyang.service.PostService;
import com.wanyang.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags="帖子发布相关api")
@RestController
@RequestMapping("post")
public class PostPublishController {

    @Autowired
    private PostService postService;


    @ApiOperation(value = "帖子发布 - 新闻")
    @PostMapping("publish/news")
    public ApiResult publishNews(@RequestBody PostPublishNews postPublishNews) {
        postPublishNews.setPostCategoryId(1);
        postService.publish(postPublishNews);
        return ApiResult.success();
    }

    @ApiOperation(value = "帖子发布 - 公益")
    @PostMapping("publish/welfare")
    public ApiResult publishWelfare(@RequestBody PostPublishWelfare postPublishWelfare) {
        postPublishWelfare.setPostCategoryId(2);
        postService.publish(postPublishWelfare);
        return ApiResult.success();
    }

    @ApiOperation(value = "帖子发布 - 租房")
    @PostMapping("publish/rental")
    public ApiResult publishWelfare(@RequestBody PostPublishRental postPublish) {
        postPublish.setPostCategoryId(4);
        postService.publish(postPublish);
        return ApiResult.success();
    }

    @ApiOperation(value = "帖子发布 - 招聘")
    @PostMapping("publish/job")
    public ApiResult publishWelfare(@RequestBody PostPublishJob postPublish) {
        postPublish.setPostCategoryId(3);
        postService.publish(postPublish);
        return ApiResult.success();
    }

    @ApiOperation(value = "帖子发布 - 招聘 - 查询工作岗位列表")
    @GetMapping("publish/jobList")
    public ApiResult jobList() {
        return ApiResult.success(postService.queryJobList(), null);
    }

    @ApiOperation(value = "帖子发布 - 二手交易")
    @PostMapping("publish/fleaMarket")
    public ApiResult publishWelfare(@RequestBody PostPublishFleaMarket postPublish) {
        postPublish.setPostCategoryId(5);
        postService.publish(postPublish);
        return ApiResult.success();
    }

}
